package com.app.widget;

import java.util.Calendar;
import java.util.Date;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.widget.RelativeLayout;

import com.app.adapter.AbstractWheelTextAdapter;

public class ReserveTimePicker extends RelativeLayout{
	public static final int MAX_WORKING_TIME = 21;
	  public static final int MIN_WORKING_TIME = 10;
	  private static final String TAG = ReserveTimePicker.class.getName();
	  private Context context;
	  TimeAdapter dayAdapter;
	  WheelView dayPicker;
	  private String[] days;
	  TimeAdapter hourAdapter;
	  WheelView hourPicker;
	  private String[] hours;

	  public ReserveTimePicker(Context paramContext)
	  {
	    super(paramContext);
	    init(paramContext);
	  }

	  public ReserveTimePicker(Context paramContext, AttributeSet paramAttributeSet)
	  {
	    super(paramContext, paramAttributeSet);
	    init(paramContext);
	  }

	  public ReserveTimePicker(Context paramContext, AttributeSet paramAttributeSet, int paramInt)
	  {
	    super(paramContext, paramAttributeSet, paramInt);
	    init(paramContext);
	  }

	  private void init(Context paramContext)
	  {
	    this.context = paramContext;
	    LayoutInflater.from(paramContext).inflate(2130903150, this);
	    this.dayPicker = ((WheelView)findViewById(2131296672));
	    this.hourPicker = ((WheelView)findViewById(2131296673));
	    findViewById(2131296674).setVisibility(8);
	    initPicker(this.dayPicker);
	    initPicker(this.hourPicker);
	    this.dayPicker.addChangingListener(new TimeChangedListener());
	    this.hourPicker.addChangingListener(new TimeChangedListener());
	    this.days = paramContext.getResources().getStringArray(2131034116);
	    this.hours = paramContext.getResources().getStringArray(2131034119);
	    initWheels();
	  }

	  private void initPicker(WheelView paramWheelView)
	  {
	    paramWheelView.setWheelBackground(0);
	    paramWheelView.setWheelForeground(2130837870);
	    paramWheelView.setShadowColor(1728053247, 1728053247, 16777215);
	  }

	  private void initWheels()
	  {
	    Calendar localCalendar = Calendar.getInstance();
	    localCalendar.setTime(new Date());
	    this.dayAdapter = new TimeAdapter(this.context, this.days);
	    this.hourAdapter = new TimeAdapter(this.context, this.hours);
	    int i = localCalendar.get(11);
	    if (i < 8)
	    {
	      this.dayAdapter.setStart(0);
	      this.hourAdapter.setStart(0);
	    }
	    while (true)
	    {
	      this.dayPicker.setViewAdapter(this.dayAdapter);
	      this.hourPicker.setViewAdapter(this.hourAdapter);
	      return;
	    }
	  }

	  private void setupWheels()
	  {
	  }

	  public Date getDate()
	  {
	    Calendar localCalendar = Calendar.getInstance();
	    localCalendar.setTime(new Date());
	    localCalendar.set(11, 0);
	    localCalendar.set(12, 0);
	    localCalendar.set(13, 0);
	    localCalendar.set(14, 0);
	    return new Date(localCalendar.getTimeInMillis() + 1000 * (60 * (60 * (24 * (this.dayPicker.getCurrentItem() + this.dayAdapter.start)))) + 1000 * (60 * (60 * (10 + (this.hourPicker.getCurrentItem() + this.hourAdapter.start)))));
	  }

	  private class TimeAdapter extends AbstractWheelTextAdapter
	  {
	    private String[] items;
	    private int start;

	    public TimeAdapter(Context paramArrayOfString, String[] arg3)
	    {
	      super(paramArrayOfString, 0);
	      setItemTextResource(2131296719);
	      Object localObject = null;
	      this.items = (String[]) localObject;
	    }

	    protected CharSequence getItemText(int paramInt)
	    {
	      return this.items[(paramInt + this.start)];
	    }

	    public int getItemsCount()
	    {
	      return this.items.length - this.start;
	    }

	    public void setItems(String[] paramArrayOfString)
	    {
	      this.items = paramArrayOfString;
	    }

	    public void setStart(int paramInt)
	    {
	      this.start = paramInt;
	    }
	  }

	  private class TimeChangedListener implements OnWheelChangedListener {

	    public void onChanged(WheelView paramWheelView, int paramInt1, int paramInt2)
	    {
	      try
	      {
	        if (paramWheelView == ReserveTimePicker.this.hourPicker)
	        {
	          if ((ReserveTimePicker.this.dayPicker.getCurrentItem() != 0) || (ReserveTimePicker.this.dayAdapter.start != 0))
	            return;
	          if (paramInt2 != 0)
	            return;
	          ReserveTimePicker.this.initWheels();
	          return;
	        }
	      }
	      catch (Exception localException)
	      {
	        localException = localException;
	        localException.printStackTrace();
	        return;
	      }
	      finally
	      {
	      }
	      if (paramWheelView == ReserveTimePicker.this.dayPicker)
	      {
	        if ((paramWheelView.getCurrentItem() == 0) && (ReserveTimePicker.this.dayAdapter.start == 0))
	        {
	          ReserveTimePicker.this.initWheels();
	          ReserveTimePicker.this.hourPicker.setCurrentItem(0);
	          return;
	        }
	        int i = ReserveTimePicker.this.hourAdapter.start;
	        int j = ReserveTimePicker.this.hourPicker.getCurrentItem();
	        ReserveTimePicker.this.hourAdapter.setStart(0);
	        ReserveTimePicker.this.hourPicker.setViewAdapter(ReserveTimePicker.this.hourAdapter);
	        ReserveTimePicker.this.hourPicker.setCurrentItem(i + j);
	      }
	    }
	  }
}
